<template>
	<view class="login">
		<view class="header">
			<text class=""></text>
			<text @click="C_loginPassword">密码登陆</text>
		</view>
		<view class="title">
			<view>手机验证码登陆</view>
			<view>输入手机号和验证码即可快速登陆</view>
		</view>
		
		<view class="form">
			<view>
				<input type="text" maxlength="11" v-model="form.mobile" placeholder="请输入手机号"/>
			</view>
			<view>
				<input type="text" v-model="form.yzm" placeholder="请输入验证码"/>
				<text @click="C_getCode">{{getCodeText}}</text>
			</view>
			<!-- <view v-if="vuex_pid">
				<input v-model="form.code+vuex_pid" disabled  style="color: rgba(0,0,0,.5)"/>
			</view> -->
		</view>
		
		<view class="submit" @click="C_submit">登陆</view>
		<view class="msg">未注册的用户将自动为您注册</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				getCodeText:'获取验证码',
				form:{
					mobile:'',
					yzm:'',
					code:'推荐码 : '
				}
			};
		},
		methods:{
			C_loginPassword(){
				uni.navigateBack()
			},
			async C_getCode(){
				let {mobile} = this.form
				if(!this.$u.utils.yz.isMobile(mobile)){this.$u.toast('请输入正确的手机号');return}
				if(this.getCodeText == '获取验证码'){
					this.$u.utils.getCode(this)
					let smsCode = await this.$u.api.send_msg({mobile})
					console.log(smsCode,'smsCode');
					if(smsCode.code != 0){
						this.$u.toast(smsCode.msg)
						this.getCodeText = '获取验证码'
					}
				}
			},
			async C_submit(){
				let {mobile,yzm} = this.form
				if(!this.$u.utils.yz.isMobile(mobile)){this.$u.toast('请输入正确的手机号');return}
				if(!yzm){this.$u.toast('请输入验证码');return}
				let params = {mobile,msg:yzm,code:this.vuex_pid}
				let smslogin = await this.$u.api.smslogin(params)
				console.log(smslogin);
				if(smslogin.code == 0){
					this.$u.vuex('vuex_token',smslogin.data.token)
					uni.reLaunch({
						url:'/pages/healthy/healthy'
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	@import "./loginCommon.scss";
</style>
